<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import = "org.json.simple.*, java.util.TreeMap, com.classes.Casemast, com.classes.CaseOutlet, java.util.ArrayList, java.net.URLEncoder, org.owasp.encoder.Encode" %>
<%@ page import = "com.mbbmap.util.Constants" %>
<%@ page import = "com.mbbmap.security.dao.*" %>
<%@ include file="/jsp/map/include/user-dao.jsp" %>	
<%@ page import="com.mbbmap.app.manager.*" %>
<%@ page import="com.mbbmap.util.*" %>
<%@ page import = "java.net.URLEncoder" %>
<%
String merchant_id = "";
String case_id = "";
String app_no = "";
String trading_name = "";
String reg_name = "";
String merchant_pic = "";
String merchant_handphone = "";

// address fields
String address = "";
String line_1 = "";
String line_2 = "";
String line_3 = "";
String line_4 = "";
String postal_code = "";
String city = "";
String region_code = "002";

String inst_status = "";
String reschedule_date = "";
JSONObject terminal_detail = new JSONObject();

JSONObject vendor_arr = null;
JSONObject vendor_details = null;

ArrayList<TreeMap<String, String>> tid_facilities = new ArrayList<TreeMap<String, String>>();
ArrayList<TreeMap<String, String>> mdr_facilities = new ArrayList<TreeMap<String, String>>();
ArrayList<TreeMap<String, String>> pos_ezypay_facilities = new ArrayList<TreeMap<String, String>>();
ArrayList<TreeMap<String, String>> amex_ezypay_facilities = new ArrayList<TreeMap<String, String>>();
JSONObject facility_tids = null;
JSONObject facilities = null;
JSONObject pos_ezypay = null;
JSONObject amex_ezypay = null;

if(request.getAttribute("m_case") != null){
	Casemast m_case = (Casemast) request.getAttribute("m_case");
	
	merchant_id = EncryptionHelper.encrypt(String.valueOf(m_case.getMerchant().getId()));
	case_id = EncryptionHelper.encrypt(String.valueOf(m_case.getId()));
	app_no = m_case.getReferenceNo();
	reg_name = m_case.getMerchant().getRegisteredName();
}


String case_outlet_opt = "<option value=\"\"></option>";

if(request.getAttribute("c_outlets") != null) {
	ArrayList<CaseOutlet> c_outlets = ((ArrayList<CaseOutlet>)request.getAttribute("c_outlets"));

	for(CaseOutlet c : c_outlets) {
		case_outlet_opt += "<option value=\"" + EncryptionHelper.encrypt(String.valueOf(c.getOutlet().getId())) + "\">" + c.getOutlet().getName() + "</option>";
	}
}

if(request.getAttribute("c_outlet") != null) {
	CaseOutlet c_outlet = (CaseOutlet) request.getAttribute("c_outlet");
	
	case_outlet_opt = case_outlet_opt.replace("<option value=\"" + EncryptionHelper.encrypt(String.valueOf(c_outlet.getOutlet().getId())) + "\">", "<option value=\"" + EncryptionHelper.encrypt(String.valueOf(c_outlet.getOutlet().getId())) + "\" selected>");
	trading_name = c_outlet.getOutlet().getName();
	
	if(c_outlet.getOutlet().getAddress().length() > 0) {
		JSONObject obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getAddress());

		line_1 = (obj.get("line_1") == null) ? "" : obj.get("line_1").toString().trim();
		line_2 = (obj.get("line_2") == null) ? "" : obj.get("line_2").toString().trim();
		line_3 = (obj.get("line_3") == null) ? "" : obj.get("line_3").toString().trim();
		line_4 = (obj.get("line_4") == null) ? "" : obj.get("line_4").toString().trim();
		postal_code = (obj.get("postal_code") == null) ? "" : obj.get("postal_code").toString().trim();
		city = (obj.get("city") == null) ? "" : obj.get("city").toString().trim();
		region_code = (obj.get("region_code") == null) ? "" : obj.get("region_code").toString().trim();
		
		if(region_code.equals("002")) {
			region_code = "002 - Sabah";
		} else if(region_code.equals("003")) {
			region_code = "003 - Sarawak";
		} else if(region_code.equals("004")) {
			region_code = "004 - Perlis";
		} else if(region_code.equals("005")) {
			region_code = "005 - Kedah";
		} else if(region_code.equals("006")) {
			region_code = "006 - Pulau Pinang";
		} else if(region_code.equals("007")) {
			region_code = "007 - Perak";
		} else if(region_code.equals("008")) {
			region_code = "008 - Kelantan";
		} else if(region_code.equals("009")) {
			region_code = "009 - Terengganu";
		} else if(region_code.equals("010")) {
			region_code = "010 - Pahang";
		} else if(region_code.equals("011")) {
			region_code = "011 - Selangor";
		} else if(region_code.equals("012")) {
			region_code = "012 - Negeri Sembilan";
		} else if(region_code.equals("013")) {
			region_code = "013 - Melaka";
		} else if(region_code.equals("014")) {
			region_code = "014 - Johor";
		} else if(region_code.equals("015")) {
			region_code = "015 - Wilayah Persekutuan";
		}
		
		if(line_1.length() > 0) { address += line_1 + "\n"; }
		if(line_2.length() > 0) { address += line_2 + "\n"; }
		if(line_3.length() > 0) { address += line_3 + "\n"; }
		if(line_4.length() > 0) { address += line_4 + "\n"; }
		if(postal_code.length() > 0) { address += postal_code + "\n"; }
		if(city.length() > 0) { address += city + "\n"; }
		if(region_code.length() > 0) { address += region_code; }
	}
	
	if(c_outlet.getPosForm().length() > 0) {
		JSONObject obj = (JSONObject) JSONValue.parse(c_outlet.getPosForm());
		
		merchant_pic = (obj.get("marchant_pic") == null) ? "" : obj.get("marchant_pic").toString();
		merchant_handphone = (obj.get("merchant_handphone") == null) ? "" : obj.get("merchant_handphone").toString();
		
		vendor_arr = (JSONObject) obj.get("vendor_arr");
		
		if(vendor_arr != null){
			if(request.getAttribute("vendor_name") != null){
				vendor_details = (JSONObject) vendor_arr.get(request.getAttribute("vendor_name"));
			}
			
			if(vendor_details != null){
				facility_tids = (vendor_details.get("facility_tids") == null ? null : (JSONObject) vendor_details.get("facility_tids"));
			}
			if(vendor_details.get("pos_ezypay_facilities") != null) {
				pos_ezypay = (JSONObject) vendor_details.get("pos_ezypay_facilities");
			}
			
			if(vendor_details.get("amex_ezypay_facilities") != null) {
				amex_ezypay = (JSONObject) vendor_details.get("amex_ezypay_facilities");
			}
			
			if(vendor_details.get("mdr_facilities") != null) {
				facilities = (JSONObject) vendor_details.get("mdr_facilities");
			}
		}
	}
	
	
	if(c_outlet.getPosInstallation().length() > 0){
		JSONObject obj = (JSONObject) JSONValue.parse(c_outlet.getPosInstallation());
		
		if(request.getAttribute("vendor_name") != null){
			JSONObject vendor_obj = (JSONObject) obj.get(request.getAttribute("vendor_name"));
			
			if(vendor_obj != null) {
				terminal_detail = (JSONObject) vendor_obj.get("terminal_detail");
				inst_status = vendor_obj.get("inst_status").toString();
				reschedule_date = vendor_obj.get("reschedule_date").toString();
			}
		}
	}
	if(c_outlet.getOutlet().getMDRRate().length() > 0) {
		JSONObject mdr_obj = (JSONObject) JSONValue.parse(c_outlet.getOutlet().getMDRRate());
		
		String[] arr = new String[] {"POS", "DCC", "MO", "TO", "RPS", "E-Commerce", "M2U", "ORS"};
		String[] arr_type = new String[] {"Wired", "Wireless", "MPOS"};
		String[] arr_ezpay = new String[] {"E3", "E6", "E9", "E12", "E18", "E24", "E36"};
		
		for(String s : arr){
			String in_mid = "";
			String in_mid_amex = "";
			
			if(s.equals("POS")){
				in_mid = mdr_obj.get("14").toString();	// VISA MASTER POS MID No
				in_mid_amex = mdr_obj.get("283").toString();	// AMEX POS Amex MID No
			} else if(s.equals("DCC")){
				in_mid = mdr_obj.get("15").toString();	// VISA MASTER DCC MID No
				//in_mid_amex = mdr_obj.get("283").toString();	// AMEX POS Amex MID No
			} else if(s.equals("MO")){
				in_mid = mdr_obj.get("16").toString();	// VISA MASTER MO MID No
				in_mid_amex = mdr_obj.get("284").toString();	// AMEX MO Amex MID No
			} else if(s.equals("TO")){
				in_mid = mdr_obj.get("17").toString();	// VISA MASTER TO MID No
				in_mid_amex = mdr_obj.get("285").toString();	// AMEX TO Amex MID No
			} else if(s.equals("RPS")){
				in_mid = mdr_obj.get("18").toString();	// VISA MASTER RPS MID No
				in_mid_amex = mdr_obj.get("286").toString();	// AMEX RPS Amex MID No
			} else if(s.equals("E-Commerce")){
				in_mid = mdr_obj.get("19").toString();	// VISA MASTER E-Commerce MID No
				in_mid_amex = mdr_obj.get("287").toString();	// AMEX E-Commerce Amex MID No
			} else if(s.equals("M2U")){
				in_mid = mdr_obj.get("20").toString();	// VISA MASTER M2U MID No
				in_mid_amex = mdr_obj.get("288").toString();	// AMEX M2U Amex MID No
			} else if(s.equals("ORS")){
				in_mid = mdr_obj.get("21").toString();	// VISA MASTER ORS MID No
				//in_mid_amex = mdr_obj.get("283").toString();	// AMEX POS Amex MID No
			}
			
			if(in_mid_amex.startsWith("01")) {
				in_mid_amex = in_mid_amex.replaceFirst("01", "920");
			}
			
			TreeMap<String, String> item = null;
			
			if(in_mid.length() > 0 || in_mid_amex.length() > 0){
				for(String t  : arr_type) {
					item = new TreeMap<String, String>();
					item.put("facility", s);
					item.put("mid_no", in_mid);
					item.put("mid_no2", in_mid_amex);
					item.put("type", t);
					item.put("first_tid", "");
					item.put("tid_items", "");
					
					if(facilities != null && facilities.get(s) != null){
						JSONObject f_type_obj = (JSONObject) facilities.get(s);
						JSONObject f_obj = (JSONObject) f_type_obj.get(t);
						item.put("first_tid", f_obj.get("first_tid").toString());
						item.put("tid_items", f_obj.get("tid_items").toString());
					}
					
					mdr_facilities.add(item);
					
					
					if(facility_tids != null) {
						if(facility_tids.get(s) != null) {
							JSONObject tid_type_obj = (JSONObject) facility_tids.get(s);
							
							if(tid_type_obj.get(t) != null) {
								JSONArray tid_obj = (JSONArray) tid_type_obj.get(t);
								
								for(int i=0; i<tid_obj.size(); i++){
									JSONObject tid_item = (JSONObject) tid_obj.get(i);
									
									String tid_no_str = tid_item.get("tid_no").toString();
									
									if(pos_ezypay != null && pos_ezypay.containsKey(tid_no_str)){
										JSONObject pos_ezypay_arr = (JSONObject) pos_ezypay.get(tid_no_str);
										
										for(String ezpay : arr_ezpay){
											if(pos_ezypay_arr.get(ezpay) == null){
												continue;
											}
											
											JSONObject pos_ezypay_item = (JSONObject) pos_ezypay_arr.get(ezpay);
											
											item = new TreeMap<String, String>();
											item.put("tid_no", pos_ezypay_item.get("tid_no").toString());
											item.put("type", pos_ezypay_item.get("type").toString());
											item.put("ezypay_plan", pos_ezypay_item.get("ezypay_plan").toString());
											item.put("mid_no", pos_ezypay_item.get("mid_no").toString());
											item.put("first_tid", pos_ezypay_item.get("first_tid").toString());
											
											pos_ezypay_facilities.add(item);
										}
										
									}
										
									
									if(amex_ezypay != null && amex_ezypay.containsKey(tid_no_str)){
										JSONObject amex_ezypay_arr = (JSONObject) amex_ezypay.get(tid_no_str);
										
										for(String ezpay : arr_ezpay){
											if(amex_ezypay_arr.get(ezpay) == null){
												continue;
											}
											
											JSONObject amex_ezypay_item = (JSONObject) amex_ezypay_arr.get(ezpay);
											
											item = new TreeMap<String, String>();
											item.put("tid_no", amex_ezypay_item.get("tid_no").toString());
											item.put("type", amex_ezypay_item.get("type").toString());
											item.put("ezypay_plan", amex_ezypay_item.get("ezypay_plan").toString());
											item.put("mid_no", amex_ezypay_item.get("mid_no").toString());
											item.put("first_tid", amex_ezypay_item.get("first_tid").toString());
											
											amex_ezypay_facilities.add(item);
										}
									}
									
								}
							}
						}
					}
				}
				
				
				
			}
		}
	}
}


if(facility_tids != null) {
	String[] arr_type = new String[] {"Wired", "Wireless", "MPOS"};
	
	for(Object s : facility_tids.keySet()){
		JSONObject tid_type_obj = (JSONObject) facility_tids.get(s);
		
		for(String t  : arr_type) {
			if(tid_type_obj.get(t) != null) {
				JSONArray tid_obj = (JSONArray) tid_type_obj.get(t);
				
				for(int i=0; i<tid_obj.size(); i++){
					JSONObject tid_item = (JSONObject) tid_obj.get(i);
					
					TreeMap<String, String> item = new TreeMap<String, String>();
					item.put("facility", s.toString());
					item.put("mid_no", tid_item.get("mid_no").toString());
					item.put("mid_no2", tid_item.get("mid_no2").toString());
					item.put("tid_no", tid_item.get("tid_no").toString());
					
					if(terminal_detail.get(tid_item.get("tid_no")) != null){
						JSONObject terminal_item = (JSONObject) terminal_detail.get(tid_item.get("tid_no"));
						
						item.put("tid_serial", terminal_item.get("tid_serial").toString());
						item.put("sim_serial", terminal_item.get("sim_serial").toString());
						item.put("sam_serial", terminal_item.get("sam_serial").toString());
						item.put("install_date", terminal_item.get("install_date").toString());
					}
					else {
						item.put("tid_serial", "");
						item.put("sim_serial", "");
						item.put("sam_serial", "");
						item.put("install_date", "");
					}
					
					tid_facilities.add(item);
				}
			}
		}
	}
}

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<jsp:include page="/jsp/map/include/html-meta.jsp" />
<script src="<%= request.getContextPath() %>/js/merchant.js"></script>
<script src="<%= request.getContextPath() %>/js/statusaction.js"></script>
<script src="<%= request.getContextPath() %>/js/vendor.js"></script>
<title>MAYBANK</title>
</head>

<body onload="vendor.vendor_inst_load('<%= merchant_id %>', '<%= case_id %>')">

<!-- Header -->
<%@ include file="/jsp/common/Header.jsp" %>	
<!-- End Header -->


<div class="row-fluid page">
	<div class="span12">

		<jsp:include page="/jsp/map/include/tab.jsp">
			
			<jsp:param name="active" value='<%=EncryptionHelper.encrypt("vendor") %>' />
		</jsp:include>
		
		<jsp:include page="/jsp/map/include/vendor-tab.jsp">
			
			<jsp:param name="active" value='<%=EncryptionHelper.encrypt("installation") %>' />
		</jsp:include>
		
		<form name="form">
		<input type="hidden" name="<%= Constants.TOKEN_KEY %>" value="<%= session.getAttribute(Action.TRANSACTION_TOKEN_KEY) %>" >
		<div class="form-horizontal">
			
			<div class="control-group">
				<label class="control-label">For Outlet</label>
				<div class="controls">
					<select id="outlet_id" name="outlet_id" style="width:220px"><%= case_outlet_opt %></select>
				</div>
			</div>
			
			<div class="control-group">
				<label class="control-label">Application No.</label>
				<div class="controls">
					<input type="text" id="app_no" name="app_no" readonly="readonly" value="<%= app_no %>" />
				</div>
			</div>
			
			<div class="control-group">
				<label class="control-label">Trading Name</label>
				<div class="controls">
					<input type="text" id="trading_name" readonly="readonly" value="<%= trading_name %>" />
				</div>
			</div>
			
			<div class="control-group">
				<label class="control-label">Registered Name</label>
				<div class="controls">
					<input type="text" id="registered_name" readonly="readonly" value="<%= reg_name %>" />
				</div>
			</div>
			
			<div class="control-group">
				<label class="control-label">Address</label>
				<div class="controls">
					<textarea id="address" readonly="readonly" style="height:60px"><%= address %></textarea>
				</div>
			</div>
			
			
			<div class="row-fluid">
				<div class="span6">
					<div class="control-group">
						<label class="control-label">Merchant PIC</label>
						<div class="controls">
							<input type="text" id="marchant_pic" name="marchant_pic" readonly="readonly" value="<%= merchant_pic %>" />
						</div>
					</div>
				</div>
				
				<div class="span6">
					
					<div class="control-group">
						<label class="control-label">Handphone No.</label>
						<div class="controls">
							<input type="text" id="merchant_handphone" name="merchant_handphone" readonly="readonly" value="<%= merchant_handphone %>" />
						</div>
					</div>
				</div>
				
			</div>
			
			
			<div class="row-fluid">
				<div class="span2 list">
				
					<ul class="outletlist">
					<%
						String outlet_id = "";
						
						if(request.getAttribute("c_outlet") != null){
							Long id = ((CaseOutlet)request.getAttribute("c_outlet")).getOutlet().getId();
							outlet_id = EncryptionHelper.encrypt(id.toString());
						}
					
					
						if(vendor_arr != null){
							String html = "";
							String css_class = "";
							
							for(Object a : vendor_arr.keySet()){
								JSONObject o = (JSONObject) vendor_arr.get(a);
								
								css_class = "";
								
								if(vendor_details != null) {
									if(vendor_details.get("name").toString().equals(o.get("name").toString())){
										css_class = " class=\"active\"";
									}
								}
								
								html = "<li" + css_class + "><a href=\"" + request.getContextPath() + "/NewApp.do?dispatch=vendor_installation&m_id=" + EncryptionHelper.encryptEncodeURL(request.getAttribute("merchant_id")+"") + "&c_id=" + EncryptionHelper.encryptEncodeURL(request.getAttribute("case_id")+"") + "&o_id=" + outlet_id + "&vendor_name=" + URLEncoder.encode(o.get("name").toString(), "ISO-8859-1") + "\">" + o.get("name").toString() + "</a></li>";
								
								out.println(html);
							}
						}
					%>
					</ul>
					
				</div>
				
				<%
					String vendor_name = "";
					String serial_no = "";
					if(vendor_details != null){
						vendor_name = vendor_details.get("name").toString();
						serial_no = vendor_details.get("serial_no").toString();
					}
				%>
				<div id="vendor_install_detail" class="span10 detail" data-name="<%=vendor_name %>">
					
					<table class="tbl vendor_inst_tbl" style="width:100%">
						<tr>
							<td style="width:20%">Form Serial No.</td>
							<td style="width:80"><input type="text" id="serial_no" name="serial_no" readonly="readonly" value="<%= serial_no %>" /></td>
						</tr>
						<tr>
							<td>Installation Status</td>
							<td>
								<% 
								String html = "<input type=\"text\" readonly=\"readonly\" value=\"" + inst_status + "\" />";
								out.println(html);
								%>
								<%-- <select id="inst_status" name="inst_status">
									<option value=""></option>
									<% 
										/* String html = "<option value=\"Successful\">Successful</option>"
											+ "<option value=\"Cancel\">Cancel</option>"
											+ "<option value=\"Reschedule\">Reschedule</option>";
										html = html.replace("value=\"" + inst_status + "\"", "value=\"" + inst_status + "\" selected "); */
										out.println(html);
									%>
								</select> --%>
							</td>
						</tr>
						<tr>
							<td>Reschedule Date</td>
							<td><input type="text" id="reschedule_date" name="reschedule_date" placeholder="ddmmyyyy" value="<%= reschedule_date %>" readonly="readonly"/></td>
						</tr>
					</table>
					
				
				
				
					<div class="form-section">
						<div class="title">Terminal Detail</div>
						<table class="tbl vendor_pos_tbl_2 terminal_detail" style="width:90%; margin-bottom:20px"><thead>
							<tr>
								<th style="width:16%">POS MID</th>
								<th style="width:16%">AMEX MID</th>
								<th style="width:18%">Terminal ID</th>
								<th style="width:15%">Terminal Serial No.</th>
								<th style="width:15%">SIM Serial No.</th>
								<th style="width:15%">SAM Serial No.</th>
								<th style="width:15%">Installation Date</th>
							</tr>
						</thead><tbody>
						<%
							for(TreeMap<String, String> item : tid_facilities){
								html = "<tr>"
									+ "	<td class=\"mid_no\"><input type=\"text\" readonly=\"readonly\" value=\"" + item.get("mid_no") + "\" /></td>"
									+ "	<td class=\"mid_no2\"><input type=\"text\" readonly=\"readonly\" value=\"" + item.get("mid_no2") + "\" /></td>"
									+ "	<td class=\"tid_no\"><input type=\"text\" readonly=\"readonly\" value=\"" + item.get("tid_no") + "\" /></td>"
									+ "	<td class=\"tid_serial\"><input type=\"text\" value=\"" + item.get("tid_serial") + "\" ></td>"
									+ "	<td class=\"sim_serial\"><input type=\"text\" value=\"" + item.get("sim_serial") + "\" ></td>"
									+ "	<td class=\"sam_serial\"><input type=\"text\" value=\"" + item.get("sam_serial") + "\" ></td>"
									+ "	<td class=\"install_date\"><input type=\"text\" placeholder=\"ddmmyyyy\" value=\"" + item.get("install_date") + "\" ></td>"
									+ "</tr>";
								
								out.println(html);
							}
						%>
						</tbody></table>
						
					</div>
					
					<div class="form-section">
					<div class="title">POS (EZYPAY)</div>
					<table class="tbl vendor_pos_tbl_2 pos_ezypay" style="width:75%; margin-bottom:20px"><thead>
						<tr>
							<th style="width:20%">POS TID</th>
							<th style="width:20%">Type</th>
							<th style="width:20%">EZYPAY Plan</th>
							<th style="width:20%">EZYPAY MID</th>
							<th style="width:20%">EZYPAY TID</th>
						</tr>
					</thead><tbody>
					<%
						String last_parent_tid = "";
						for(TreeMap<String, String> item : pos_ezypay_facilities){
							String read_only = "readonly=\"readonly\"";
							
							if(item.get("tid_no").equals(last_parent_tid) == false) {
								read_only = "";
								last_parent_tid = item.get("tid_no");
							}
							
							html = "<tr data-tid=\"" + item.get("tid_no") + "\">"
								+ "	<td class=\"tid_no\"><input type=\"text\" readonly=\"readonly\" value=\"" + item.get("tid_no") + "\" /></td>"
								+ "	<td class=\"type\"><input type=\"text\" readonly=\"readonly\" value=\"" + (item.get("type") == null ? "" : item.get("type") ) + "\" /></td>"
								+ "	<td class=\"ezypay_plan\"><input type=\"text\" readonly=\"readonly\" value=\"" + item.get("ezypay_plan") + "\" /></td>"
								+ "	<td class=\"mid_no\"><input type=\"text\" readonly=\"readonly\" value=\"" + item.get("mid_no") + "\" /></td>"
								+ "	<td class=\"first_tid\"><input type=\"text\" " + read_only + " value=\"" + item.get("first_tid") + "\" /></td>"
								+ "</tr>";
							
							out.println(html);
						}
					%>
					</tbody></table>
				</div>
				
				
				
				<div class="form-section">
					<div class="title">AMEX (EZYPAY)</div>
					<table class="tbl vendor_pos_tbl_2 amex_ezypay" style="width:75%; margin-bottom:20px"><thead>
						<tr>
							<th style="width:20%">POS TID</th>
							<th style="width:20%">Type</th>
							<th style="width:20%">EZYPAY Plan</th>
							<th style="width:20%">EZYPAY MID</th>
							<th style="width:20%">EZYPAY TID</th>
						</tr>
					</thead><tbody>
					<%
						last_parent_tid = "";
						for(TreeMap<String, String> item : amex_ezypay_facilities){
							String read_only = "readonly=\"readonly\"";
							
							if(item.get("tid_no").equals(last_parent_tid) == false) {
								read_only = "";
								last_parent_tid = item.get("tid_no");
							}
							
							html = "<tr data-tid=\"" + item.get("tid_no") + "\">"
								+ "	<td class=\"tid_no\"><input type=\"text\" readonly=\"readonly\" value=\"" + item.get("tid_no") + "\" /></td>"
								+ "	<td class=\"type\"><input type=\"text\" readonly=\"readonly\" value=\"" + item.get("type") + "\" /></td>"
								+ "	<td class=\"ezypay_plan\"><input type=\"text\" readonly=\"readonly\" value=\"" + item.get("ezypay_plan") + "\" /></td>"
								+ "	<td class=\"mid_no\"><input type=\"text\" readonly=\"readonly\" value=\"" + item.get("mid_no") + "\" /></td>"
								+ "	<td class=\"first_tid\"><input type=\"text\" " + read_only + " value=\"" + item.get("first_tid") + "\" /></td>"
								+ "</tr>";
							
							out.println(html);
						}
					%>
					</tbody></table>
				</div>
					
					<div class="form-section">
						<div class="title">Remarks</div>
						
						<table class="tblDetails" style="width:90%"><thead>
							<tr>
								<th style="width:50%">Note / Comment</th>
								<th style="width:15%">Status</th>
								<th style="width:15%">By</th>
								<th style="width:20%">Date</th>
							</tr>
						</thead><tbody>
						<%
						if(request.getAttribute("c_outlet") != null) {
							ArrayList<TreeMap<String, String>> histArr = ((CaseOutlet) request.getAttribute("c_outlet")).getInstallNotes();
							if(histArr != null){
								int n = 0;
								for(TreeMap<String, String> histLog : histArr){
									html = "<tr class=" + (n % 2 > 0 ? "alt" : "even") + ">"
									+ "	<td>" + Encode.forHtml(histLog.get("note")) + "</td>"
									+ "	<td>" + Encode.forHtml(histLog.get("status")) + "</td>"
									+ "	<td>" + Encode.forHtml(histLog.get("created_by")) + "</td>"
									+ "	<td>" + Casemast.formatCreatedDate("dd/MM/yyyy HH:mm", Long.parseLong(histLog.get("created_date"))) + "</td>"
									+ "</tr>";
									
									out.println(html);
									++n;
								}
							}
						}
						%>
						</tbody></table>
						
						<!-- <table style="width:100%">
							<tr>
								<td style="width:20%">Remark</td>
								<td style="width:80%"><textarea id="remark" name="remark" style="height:60px; width:450px" readonly="readonly"></textarea></td>
							</tr>
						</table> -->
					</div>
					
				</div>
			</div>
			
			<div class="btn-control">
				<input id="click_redirect" name="click_redirect" type="hidden" value="" />
				<button type="button" id="submit" class="btn" onclick="vendor.create_vendor_installation2('<%= merchant_id %>', '<%= case_id %>');" style="display: none;">Save</button>
			</div>
		
		</div>
		</form>
		
	</div>
</div>

<!-- Footer -->
<%@ include file="/jsp/common/Footer.jsp" %>	
<!-- End Footer -->


</body>
</html>